package br.com.caelum.controller;

import java.math.BigDecimal;
import java.util.List;

import br.com.caelum.dao.MatriculaDAO;
import br.com.caelum.model.Matricula;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;

@Resource
public class MatriculasController {
	private final MatriculaDAO dao;
	private final Result result;
	
	public MatriculasController(MatriculaDAO dao, Result result) {
		this.dao = dao;
		this.result = result;
	}
	
	public void adiciona(Matricula matricula) {
		matricula.setNota1(new BigDecimal(0.0));
		matricula.setNota2(new BigDecimal(0.0));
		matricula.setNota3(new BigDecimal(0.0));
		matricula.setNota4(new BigDecimal(0.0));
		matricula.setMedia(new BigDecimal(0.0));
		dao.salva(matricula);
		result.redirectTo(AlunosController.class).lista();
	}
	
	public void altera(Matricula matricula) {
		dao.atualiza(matricula);
		result.redirectTo(AlunosController.class).lista();
	}
	
	public Matricula edita(Long id) {
		return dao.carrega(id);
	}
	
	public List<Matricula> listaPorAluno(Long id) {
		return dao.listaPorAluno(id);
	}
	
	public List<Matricula> listaPorTurma(Long id) {
		return dao.listaPorTurma(id);
	}
	
	public void formulario() {
	}
}
